<template>
  <div>
    <el-form
      :model="entity"
      :rules="rules"
      ref="form"
      label-width="100px"
      class="dialog-form"
    >
      <el-row :span="24">
        <el-col :span="12">
          <el-form-item style="width: 100%" label="排序" prop="sortNo">
            <el-input
              :disabled="disabled"
              placeholder="排序"
              v-model="entity.sortNo"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            style="width: 100%"
            label="业务类型"
            prop="businessType"
          >
            <el-input
              :disabled="disabled"
              placeholder="业务类型"
              v-model="entity.businessType"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="激活" prop="active">
            <el-select
              style="width: 100%"
              v-model="entity.active"
              :disabled="disabled"
            >
              <el-option :key="true" :value="true" :label="'是'"></el-option>
              <el-option :key="false" :value="false" :label="'否'"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="配置名称" prop="name">
            <el-input
              :disabled="disabled"
              placeholder="配置名称"
              v-model="entity.name"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="编码" prop="code">
            <el-input
              :disabled="disabled"
              placeholder="编码"
              v-model="entity.code"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="配置值" prop="value">
            <el-input
              :disabled="disabled"
              placeholder="配置值"
              v-model="entity.value"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="数据类型" prop="dataType">
            <el-select
              style="width: 100%"
              v-model="entity.dataType"
              :disabled="disabled"
            >
              <el-option
                :key="700"
                :value="700"
                :label="'700--字符'"
              ></el-option>
              <el-option
                :key="701"
                :value="701"
                :label="'701--INT'"
              ></el-option>
              <el-option
                :key="702"
                :value="702"
                :label="'702--DECIMAL'"
              ></el-option>
              <el-option
                :key="703"
                :value="703"
                :label="'703--DATE'"
              ></el-option>
              <el-option
                :key="704"
                :value="704"
                :label="'704--DATETIME'"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item style="width: 100%" label="最后操作人" prop="updatedBy">
            <el-input
              disabled
              placeholder="最后操作人"
              v-model="entity.username"
            >
            </el-input>
          </el-form-item>
        </el-col>
                <el-col :span="24">
          <el-form-item style="width: 100%" label="备注" prop="remark">
            <el-input
              type="textarea"
              :rows="2"
              :disabled="disabled"
              placeholder="备注"
              v-model="entity.remark"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<style lang="less" scoped>
.productLogo .el-upload-dragger {
  img {
    width: 200px;
    height: 100px !important;
  }
}

.clsCommon {
  margin-top: 10px;
  margin-left: -15px;
  margin-right: 15px;
}

.dialog-form {
  .el-radio-group {
    .el-radio {
      display: flex;
      align-items: center;
    }

    label {
      height: 40px;
    }
    .group-text {
      display: inline-block;
      width: 100px;
    }
    .title-text {
      display: inline-block;
      width: 120px;
    }
  }
}
</style>

<script>
// import ProductTypeSelect from '@/components/widgets/dongxw/ProductTypeSelect.vue';

const defaultEntity = {
  configId: null, //  配置标识
  departmentId: 0, //  部门标识
  sortNo: 0, //  排序
  businessType: "basic", //  业务类型
  active: false, //  激活状态
  name: "0", //  配置名称
  code: "0", //  编码
  value: "0", //  配置值
  dataType: 0, //  数据类型
  remark: "0", //  备注
  algorithm: 0, //  算法
  updatedBy: 0, //  最后操作人
  updatedAt: null, //  操作时间
};
export default {
  components: {},
  data() {
    return {
      isShow: true,
      multiple: true,
      isExp: false,
      activeName: "productInfo",

      ruleTpl: { when: null, then: null },
      entity: _.cloneDeep(defaultEntity),
      dateRange: [],
      oldProps: [],
      ruleDefs: [],
      isDisabled: false,
      limitTotal: false,
      rules: {
        code: [
          {
            required: true,
          },
        ],
      },
    };
  },
  computed: {
    cbm: {
      get() {
        let v = this.entity.obSize.split("*");

        if (v.length === 3) {
          var multi = function (a, b) {
            return parseInt(a) * parseInt(b);
          };
          return (v.reduce(multi, 1) / 1000000).toFixed(4);
        }
        return 0;
      },
    },
  },
  methods: {
    clearImg() {
      this.entity.picUrl = null;
    },

    funHandleChange(imgRemarkArray) {},

    getProps(scope) {
      return this.entity.props.filter((p) => p.propScope == scope);
    },
    onRuleDefsLoaded(opts) {
      this.ruleDefs = opts || [];
      this.resetProps();
    },

    resetProps() {},
    setValues(vals) {
      this.resetEntity = _.cloneDeep(vals);
      this.entity = _.cloneDeep(this.resetEntity);
    },
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let params = Object.assign({}, this.entity);

          this.$api.attend.attend.ConfigService.save(params).then((rsp) => {
            this.$msgJsonResult(rsp);
            this.$emit("saved", rsp);
          });
        }
      });
    },
    resetForm() {
      this.entity = _.cloneDeep(defaultEntity);
      if (!this.entity.configId) {
        this.entity.updatedAt = this.$dongxwDict.formatDateZero(new Date());
      }
    },
    init(options) {
      this.resetForm();
      if (options.configId) {
        this.$api.attend.attend.ConfigService.findById(options.configId).then((r) => {
          this.entity = r.data;
        });
      } else {
        this.isDisabled = false;
      }
    },
  },
  mounted() {
    this.$on("init", this.init);
    this.$on("submit", this.submitForm);
  },
};
</script>
